﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.EditorExt;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.GlobeCore;
using ESRI.ArcGIS.NetworkAnalysis;
using ESRI.ArcGIS.Output;
using ESRI.ArcGIS.SystemUI;
using DIWAGIS.Modules;
namespace DIWAGIS.Class
{
    class WorkingWithTable
    {
        public ITable CreateQueryTable(IWorkspace workspace, IQueryDef queryDef, String tableName)
        {
            // Create a reference to a TableQueryName object.
            IQueryName2 queryName2 = new TableQueryNameClass();
            queryName2.PrimaryKey = "";

            // Specify the query definition.
            queryName2.QueryDef = queryDef;

            // Get a name object for the workspace.
            IDataset dataset = (IDataset)workspace;
            IWorkspaceName workspaceName = (IWorkspaceName)dataset.FullName;

            // Cast the TableQueryName object to the IDatasetName interface and open it.
            IDatasetName datasetName = (IDatasetName)queryName2;
            datasetName.WorkspaceName = workspaceName;
            datasetName.Name = tableName;
            IName name = (IName)datasetName;

            // Open the name object and get a reference to a table object.
            ITable table = (ITable)name.Open();
            return table;
        }
    }
}

